42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

學習 Git (6) - 修改 commit 紀錄 part 2: Reset

學習 Git (6) - 修改 commit 紀錄 part 2: Reset

[Swift 學習筆記] Closure : Inline function process

[Swift 學習筆記] Closure : Inline function process

MAC PHP執行發生錯誤 在 Chrome 上顯示 Error 500

MAC PHP執行發生錯誤 在 Chrome 上顯示 Error 500


Comments